#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
检查文件中特定行的十六进制表示，查找不可见字符
"""

with open('d:/未知/yolo_apply/video_processing/video_processor.py', 'rb') as f:
    lines = f.readlines()

# 检查第1849行（0-based索引是1848）
error_line_index = 1848
print(f"检查第{error_line_index+1}行的十六进制表示:")
print("-" * 60)

if error_line_index < len(lines):
    line = lines[error_line_index]
    print(f"原始行长度: {len(line)} 字节")
    print("十六进制表示:")
    
    # 打印每行的十六进制表示，每行16字节
    for i in range(0, len(line), 16):
        chunk = line[i:i+16]
        hex_part = ' '.join(f'{b:02x}' for b in chunk)
        ascii_part = ''.join(chr(b) if 32 <= b <= 126 else '.' for b in chunk)
        print(f"{i:04x}: {hex_part:<47} {ascii_part}")
    
    # 特别检查缩进字符
    indent_end = 0
    for b in line:
        if b == ord(' ') or b == ord('\t'):
            indent_end += 1
        else:
            break
    
    indent_chars = line[:indent_end]
    print(f"\n缩进部分 ({indent_end} 字节):")
    for i, b in enumerate(indent_chars):
        char_name = 'SPACE' if b == ord(' ') else 'TAB' if b == ord('\t') else f'CHAR({b})'
        print(f"  位置 {i}: 0x{b:02x} ({char_name})")
    
    # 检查前后几行
    print("\n检查前后几行的缩进:")
    for j in range(max(0, error_line_index-2), min(len(lines), error_line_index+3)):
        if j == error_line_index:
            print(f"第{j+1}行 [错误行]:", end=' ')
        else:
            print(f"第{j+1}行:", end=' ')
        
        # 分析缩进
        line_j = lines[j]
        indent_j = 0
        for b in line_j:
            if b == ord(' ') or b == ord('\t'):
                indent_j += 1
            else:
                break
        
        # 计算空格和制表符数量
        spaces = sum(1 for b in line_j[:indent_j] if b == ord(' '))
        tabs = sum(1 for b in line_j[:indent_j] if b == ord('\t'))
        
        print(f"缩进长度={indent_j}, 空格={spaces}, 制表符={tabs}")
else:
    print(f"错误: 文件只有 {len(lines)} 行，无法检查第{error_line_index+1}行")